<?php
	require_once "includes/pagination.php";	
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=mylist'; </script>";
	}
	$userId = $_SESSION['user_id_sess'];	
	//s_asc.png
	//s_desc.png
	if($_REQUEST['by']=="asc")
	{
		$by='desc';
	}
	else
	{
		$by='asc';
	}
	
	if($_REQUEST['by']=="asc")
	{
		$asc_desc='asc';
	}
	else if($_REQUEST['by']=="desc")
	{
		$asc_desc='desc';
	}
	else
	{
		$asc_desc='desc';
	}
	
	if($_REQUEST['ord']=="1")
	{
		$ord_by='i.item_id';
	}
	else if($_REQUEST['ord']=="2")
	{
		if($_SESSION['user_type_sess']=="3")
		{
			$ord_by='i.owner_id';
		}
		else if($_SESSION['user_type_sess']=="2" || $_SESSION['user_type_sess']=="4")
		{
			$ord_by='i.seller_id';
		}
		else
		{
			$ord_by='i.owner_id';
		}
	}
	else if($_REQUEST['ord']=="3")
	{
		$ord_by='u.first_name';
	}
	else if($_REQUEST['ord']=="4")
	{
		$ord_by='o.transaction_ID';
	}
	else if($_REQUEST['ord']=="5")
	{
		$ord_by='o.order_date';
	}
	else if($_REQUEST['ord']=="6")
	{
		$ord_by='o.shipped_date';
	}
	else if($_REQUEST['ord']=="7")
	{
		$ord_by='o.shipped_verified';
	}
	else
	{
		$ord_by='order_id';
	}
	
	if(isset($_POST['btnVerify']))
	{
		$sqlSelItem="SELECT * FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id  where verify_code='".$_POST['txtItem_Code']."' ";
		$rstSelItem=mysql_query($sqlSelItem);
		$rowSelItem=mysql_fetch_array($rstSelItem);
		if(is_array($rowSelItem))
		{
			//if($userId==$rowSelItem['ordered_by'])
//			{
//				if($rowSelItem['shipped_verified']=="0")
//				{
//					$sqlPost="update tbl_orders set shipped_verified='1' where verify_code='".$_POST['txtItem_Code']."' ";
//					$rstPost=mysql_query($sqlPost) or die(mysql_error());
//					$msg="Your product shippment has been verified successfully.";
//				}
//				else
//				{
//					$msg="Your product shippment already has been verified.";
//				}
//			}
//			else
//			{
				$sqlSel_Item="select p.*,i.seller_id,i.owner_id from tbl_items i left join tbl_product p  on i.product_id=p.product_id where item_id=".$rowSelItem['item_id']."";
				$rstSel_Item=mysql_query($sqlSel_Item);
				$rowSel_Item=mysql_fetch_array($rstSel_Item);
				if(is_array($rowSel_Item))
				{
					if($rowSel_Item['owner_id']==$userId)
					{
						if($rowSelItem['shipped_date']=="")
						{
							$sqlPost="update tbl_orders set shipped_date=Now(),shipped_verified='1' where verify_code='".$_POST['txtItem_Code']."' ";
							$rstPost=mysql_query($sqlPost) or die(mysql_error());
							$msg="This product's Pick Up has been verified successfully.";
						}
						else
						{
							$msg="This product has been already verified.";
						}
					}
					else if($rowSel_Item['owner_id']==0)
					{
						if($rowSel_Item['seller_id']==$userId)
						{
							if($rowSelItem['shipped_date']=="")
							{
								$sqlPost="update tbl_orders set shipped_date=Now(),shipped_verified='1' where verify_code='".$_POST['txtItem_Code']."' ";
								$rstPost=mysql_query($sqlPost) or die(mysql_error());
								$msg="This product's Pick Up has been verified successfully.";
							}
							else
							{
								$msg="This product has been already verified.";
							}
						}
					}
					else
					{
						$msg="You are not the owner of this product code.";
					}					
				}
				else
				{
					$msg="No product code found.";
				}	
			//}
			
			//$product_name=$rowSelItem['product_name'];
			//$seller_id=$rowSelItem['seller_id'];
			///$product_id=$rowSelItem['product_id'];
		}	
		
	}
	else
	{
		$msg="";
	}
	
	
	  
	ini_set('display_errors', 1); 
	ini_set('error_reporting', 'E_error'); 				
	
	$total=0;			
	if (isset($_GET['page']) && (int)$_GET['page'] > 0) 
	{
	       $pageNumber = (int)$_GET['page'];		
	} 
	else 
	{
	       $pageNumber = 1;		
	}
	
	if((int)$_SESSION['user_type_sess']==1)
	{
		$sql_shocat="SELECT *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id where ordered_by='".$_SESSION['user_id_sess']."'  order BY ".$ord_by."  ".$asc_desc." ";//limit ".$pageNumber.", ".$itemPerPage."";
		$tot_qry = mysql_query($sql_shocat) or die(mysql_error());
		$tot_count = mysql_num_rows($tot_qry);
		$ssql_shocat="SELECT order_id,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id where ordered_by='".$_SESSION['user_id_sess']."'  AND shipped_date!='' order BY ".$ord_by."  ".$asc_desc." ";//limit ".$pageNumber.", ".$itemPerPage."";
		$s_qry = mysql_query($ssql_shocat) or die(mysql_error());
		$s_count = mysql_num_rows($s_qry);
		$new_count = $tot_count - $s_count;
	}
	else if((int)$_SESSION['user_type_sess']==2 || (int)$_SESSION['user_type_sess']==4)
	{
		$sql_shocat="SELECT *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or ordered_by='".$_SESSION['user_id_sess']."')  order BY ".$ord_by."  ".$asc_desc."";//limit ".$pageNumber.", ".$itemPerPage."";
		$tot_qry = mysql_query($sql_shocat) or die(mysql_error());
		$tot_count = mysql_num_rows($tot_qry);
		$ssql_shocat="SELECT order_id,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or ordered_by='".$_SESSION['user_id_sess']."') AND shipped_date!=''  order BY ".$ord_by."  ".$asc_desc."";//limit ".$pageNumber.", ".$itemPerPage."";
		$s_qry = mysql_query($ssql_shocat) or die(mysql_error());
		$s_count = mysql_num_rows($s_qry);
		$new_count = $tot_count - $s_count;
	}
	else if((int)$_SESSION['user_type_sess']==3)
	{
	       
		$sql_shocat="SELECT *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or owner_id='".$_SESSION['user_id_sess']."')  order BY ".$ord_by."  ".$asc_desc." ";//limit ".$pageNumber.", ".$itemPerPage."";
		$tot_qry = mysql_query($sql_shocat) or die(mysql_error());
		$tot_count = mysql_num_rows($tot_qry);
		$ssql_shocat="SELECT order_id,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or owner_id='".$_SESSION['user_id_sess']."') AND shipped_date!='' order BY ".$ord_by."  ".$asc_desc." ";//limit ".$pageNumber.", ".$itemPerPage."";
		$s_qry = mysql_query($ssql_shocat) or die(mysql_error());
		$s_count = mysql_num_rows($s_qry);
		$new_count = $tot_count - $s_count;
	}
	else
	{
		$sql_shocat="SELECT *,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or ordered_by='".$_SESSION['user_id_sess']."' or owner_id='".$_SESSION['user_id_sess']."')  order BY ".$ord_by."  ".$asc_desc."";//limit ".$pageNumber.", ".$itemPerPage."";
		$tot_qry = mysql_query($sql_shocat) or die(mysql_error());
		$tot_count = mysql_num_rows($tot_qry);
		$ssql_shocat="SELECT order_id,DATE_FORMAT(order_date,GET_FORMAT(DATE,'USA')) as tran_date,DATE_FORMAT(shipped_date,GET_FORMAT(DATE,'USA')) as ship_date FROM tbl_orders o LEFT JOIN tbl_users u ON o.ordered_by = u.user_id left join tbl_items i on o.item_id=i.item_id  where (seller_id='".$_SESSION['user_id_sess']."' or ordered_by='".$_SESSION['user_id_sess']."' or owner_id='".$_SESSION['user_id_sess']."') AND shipped_date!=''  order BY ".$ord_by."  ".$asc_desc."";//limit ".$pageNumber.", ".$itemPerPage."";
		$s_qry = mysql_query($ssql_shocat) or die(mysql_error());
		$s_count = mysql_num_rows($s_qry);
		$new_count = $tot_count - $s_count;
	}
	
?>	
<style type="text/css">
	#sell-form { border:0px solid #CCC; padding:10px; float:left; vertical-align:top; width:93%; margin:2%; }

	#sell-form label{
	float: left;
	width: 130px;
	font-weight: bold;
	}
	
	#sell-form input, select, textarea{	
	width: 280px;
	margin-bottom: 5px;
	font-size:12px;	
	}
	
	#sell-form textarea{
	height: 250px;
	width: 450px;
	font-size:12px;
	}
	
	#sell-form a{
		float:left;
	}
	
	#sell-form #submitbutton{
	margin-left: 130px;
	margin-top: 5px;
	width: 90px;
	}
	
	#sell-form #sellby-div { float:left;  }
	
	#sell-form #sellby-div label { width: 70px; margin-bottom:2px; font-weight:normal; }
	#sell-form #sellby-div input { width: 1px; }
	
	#sell-form br{
	clear: left;
	}

	
</style>
<div id='panel'>
<a name="transaction_history"></a>
<div class="fulldiv" style="width:700px;">

<div class="fulldiv" style="margin:10px 0px 0px 0px;">
       <div style="float:left; margin:0px 10px 0px 10px; padding-top:8px;"><strong class="orangehead">Transaction History</strong></div>
       <div class="greyarrowsml" onclick="show_hide_s_boxes('tran_history')" id="arrow_tran_history">&nbsp;</div>
       <?php if($new_count!=0) { ?>
       <div style="float:left; width:150px; padding:5px 0px 0px 15px; color:#6B6767; font-size:14px;" id="count_box_tran_history"><?php echo $new_count." NEW";?></div>
       <?php } ?>
       <div class="greytab_out" id="other1_tran_history">
	       <div class="greytab_left">&nbsp;</div>
	       <div class="greytab_repeat">Sort</div>
	       <div class="greytab_right">&nbsp;</div>
	       <span style="float:left; margin:0px 0px 10px 0px;">&nbsp;</span>		
	       <div class="greytab_left">&nbsp;</div>
	       <div class="greytab_repeat" style="cursor:pointer;" onclick="return validatechk();"  id="ref">Refund Transaction</div>
	       <div class="greytab_right">&nbsp;</div>
       </div>
</div>
<div id="tran_history">
<div class="fullbox_top">&nbsp;</div>
<div class="fullbox_repeat">

<form name="form_his" id="form_his" method="post">
	<div style="float: left; width: 660px; border:0px;" id='suc-msg'><?php echo $msg;?></div>
	<div style="float: left; width: 660px; border-bottom:2px solid #ccc;">
		<div style="width: 15px;" class="cell_head">&nbsp;</div>
		<div class="cell_head" style="width: 85px;"><a href="index.php?mySwapen&ord=1&by=<?php echo $by;?>">Product</a></div>
		<?php if((int)$_SESSION['user_type_sess']==2) { ?> 
		<div class="cell_head" style="width: 85px; text-align:center;"><a href="index.php?mySwapen&ord=3&by=<?php echo $by;?>">Sold To</a></div>
		<div class="cell_head" style="width: 85px;">Purchased From</div>
		<?php } else if((int)$_SESSION['user_type_sess']!=1) { ?>
		<div class="cell_head" style="width: 85px; text-align:center;"><a href="index.php?mySwapen&ord=3&by=<?php echo $by;?>">User</a></div>
		<div class="cell_head" style="width: 85px; text-align:center;">Sold By</div>
		<?php } else { ?>
		<div class="cell_head" style="width: 85px;">Transaction</div>
		<div class="cell_head" style="width: 85px;"><a href="index.php?mySwapen&ord=3&by=<?php echo $by;?>">User</a></div>
		<?php } ?>
		<div class="cell_head" style="width: 85px;"><a href="index.php?mySwapen&ord=4&by=<?php echo $by;?>">Transaction #</a></div>
		<div class="cell_head" style="width: 80px; text-align:center;"><a href="index.php?mySwapen&ord=5&by=<?php echo $by;?>">Transaction Date</a></div>
		<div class="cell_head" style="width: 80px; text-align:center;"><a href="index.php?mySwapen&ord=7&by=<?php echo $by;?>">Shipped <br />(Picked up)</a></div>
		<div class="cell_head" style="width: 80px;">&nbsp;</div>
	</div>


  
  	
	
	<div style="max-height:380px; overflow-y:auto; overflow-x:hidden; width:660px; float:left;" id="tbox">
	  
	<?php 
	
	$itemPerPage=15;
	//echo $sql_shocat;
	$rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));
	$numRows = mysql_num_rows($rst_shocat);
				 
	$i=(int)(($itemPerPage*($pageNumber-1))+1);
				 
	if($numRows>0)
	{
		$j=0;
		while($row_shocat = mysql_fetch_array($rst_shocat)) 
		{					
													
			$sqlSelItem="select p.*,i.seller_id,i.owner_id from tbl_items i left join tbl_product p  on i.product_id=p.product_id where item_id=".$row_shocat['item_id']."";
			$rstSelItem=mysql_query($sqlSelItem);
			$rowSelItem=mysql_fetch_array($rstSelItem);
			if(is_array($rowSelItem))
			{
				$product_name=$rowSelItem['product_name'];
				$seller_id=$rowSelItem['seller_id'];
				$product_id=$rowSelItem['product_id'];
				
				$owner_id=$rowSelItem['owner_id'];
			}
			$product_id=$rowSelItem['product_id'];
			if($row_shocat['isWhole']=='0')
			{
									
				if($userId==$row_shocat['ordered_by'])
				{
					$tans="Purchased From";
					$user=$seller_id;
					//$editItem="<a href='sendowner.php?ownerid=".$seller_id."&jobid=".$product_id."&type=M' target='_blank' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";	
				}
				else if($userId==$row_shocat['seller_id'])
				{
					$tans="Purchased From";
					$user=$owner_id;
					//$editItem="<a href='sendowner.php?ownerid=".$row_shocat['ordered_by']."&jobid=".$product_id."&type=M' target='_blank' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";	
					
					$tans1="Sold To";
					$user1=$row_shocat['ordered_by'];
				}
				else if($userId==$row_shocat['owner_id'])
				{
					$tans="Purchased By";
					$user=$seller_id;
					//$editItem="<a href='sendowner.php?ownerid=".$seller_id."&jobid=".$product_id."&type=M' target='_blank' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";	
					
					$tans1="Sold To";
					$user1=$row_shocat['ordered_by'];
				}
				else
				{
					$tans="Sold To";
					$user=$row_shocat['ordered_by'];
					//$editItem="<a href='sendowner.php?ownerid=".$user."&jobid=".$product_id."&type=M' target='_blank' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";
					
				}	
				
				$editItem="<a href='javascript:void(0);' onclick='show_contact_user_box($seller_id,$product_id,\"$product_name\")' id='contact_user_$product_id' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";		
				$sqlSelItem="select * from tbl_users where user_id='".$user."'";
				$rstSelItem=mysql_query($sqlSelItem);
				$rowSelItem=mysql_fetch_array($rstSelItem);						
				if(is_array($rowSelItem))
				{
					$order_by=$rowSelItem['first_name'];
				}
				else
				{
					$order_by="";
				}
				if($userId==$row_shocat['seller_id'] || $userId==$row_shocat['owner_id'])
				{
					$sqlSelItem1="select * from tbl_users where user_id='".$user1."'";
					$rstSelItem1=mysql_query($sqlSelItem1);
					$rowSelItem1=mysql_fetch_array($rstSelItem1);						
					if(is_array($rowSelItem1))
					{
						$user_by=$rowSelItem1['first_name'];
					}
					else
					{
						$user_by="";
					}
				}
			}
			else
			{
				$order_by_id=$row_shocat['ordered_by'];
				$product_id=$row_shocat['item_id'];
											
				
				$sqlSelItem="select * from tbl_users where user_id='".$order_by_id."'";
				$rstSelItem=mysql_query($sqlSelItem);
				$rowSelItem=mysql_fetch_array($rstSelItem);						
				if(is_array($rowSelItem))
				{
					$user_by=$rowSelItem['first_name'];
				}
				else
				{
					$user_by="";
				}
				
				$sqlSelItem_prod="select * from tbl_wholeseller_product where product_id='".$product_id."'";
				$rstSelItem_prod=mysql_query($sqlSelItem_prod);
				$rowSelItem_prod=mysql_fetch_array($rstSelItem_prod);
				if(is_array($rowSelItem_prod))
				{
					$sold_by_id=$rowSelItem_prod['posted_by'];
					$product_name=$rowSelItem_prod['product_name'];
				}
				else
				{
					$sold_by_id="0";
				}
				
				$sqlSelItem="select * from tbl_users where user_id='".$sold_by_id."'";
				$rstSelItem=mysql_query($sqlSelItem);
				$rowSelItem=mysql_fetch_array($rstSelItem);						
				if(is_array($rowSelItem))
				{
					$order_by=$rowSelItem['first_name'];
				}
				else
				{
					$order_by="";
				}
				$editItem="<a href='javascript:void(0);' onclick='show_contact_user_box($sold_by_id,$product_id,\"$product_name\")' id='contact_user_$product_id' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";		
										
			}
						
						
			if($row_shocat['shipped_verified']==1)
			{
				$shipped='<font style="font-weight:bold; color:pink" title="Local Pickup">P</font>';
			}
			else
			{
				$shipped="";
			}
			if($row_shocat['shipped_date']!="")
			{
				$shipped_date=$row_shocat['ship_date'];
			}
			else
			{
				//echo "hi".$product_id;
				if($row_shocat['is_online']==0)
				{
					$shipped_date="Not Yet <img src='images/down_arrow.png' align='absmiddle' title='Verify' id='down_arrow_".$product_id."' style='cursor:pointer;' onclick='show_ship_verify_box($product_id)' />";
				}
				else
				{
					$shipped_date="Not Yet <img src='images/down_arrow.png' align='absmiddle' title='Verify' id='down_arrow_".$product_id."' style='cursor:pointer;' onclick='show_ship_verify_box($product_id)' />";
				}
			}					
						
						
			$transaction_ID = substr($row_shocat['transaction_ID'],0,10);
			
			$p = '';
			if($product_id!='') {
				$lpqry = mysql_query("select localPickup from tbl_product where product_id=$product_id") or die();
				$cpqry = mysql_num_rows($lpqry);
				if($cpqry > 0)
				{
					$product = mysql_fetch_array($lpqry);
					$localPickup = $product['localPickup'];
				
					if($localPickup==1)
					$p = '<font style="font-weight:bold; color:pink" title="Local Pickup">P</font>';
				}
			}
			
			$chn_css = 'style="float:left; width:659px; border-bottom:1px solid #ccc; margin:3px 0px 3px;"';
			if(($row_shocat['refund']==1) && ($row_shocat['refund_comm']==0)) {
				$chn_css = 'style="float:left; width:659px; border-bottom:1px solid #ccc; margin:3px 0px 3px; background:#F7DEDE;" title="Owner Commission not refunded yet"';
			}
			?> 
			<div <?php echo $chn_css;?>>
				
				<div style="width: 15px;" class="cell_row">
					<?php
					if($userId==$row_shocat['order_comm_by_user_id'])
					{
						if($row_shocat['refund']==0) { ?>	
							<input type="radio" name="chk" value="<?php echo $row_shocat['transaction_ID'];?>" style=" margin:3px 0px 0px 0px;" />
						<? } else { echo '&nbsp;';} 
					}
					else
					{
						if(($row_shocat['refund']==1) && ($row_shocat['refund_comm']==0)) { ?>	
							<input type="radio" name="chk" value="<?php echo $row_shocat['transaction_ID'];?>" style=" margin:3px 0px 0px 0px;" />
						<? } else { echo '&nbsp;';} 
					}
					?>
				</div>
				<div class="cell_row" style="width: 85px;"><?php if($product_name!='') echo $product_name; else echo '&nbsp;';?></div>
				<?php if((int)$_SESSION['user_type_sess']!=1) { ?>
				<div class="cell_row" style="width: 85px; text-align:center;"><?php if($user_by!='') echo $user_by; else echo '&nbsp;';?></div>
				<div class="cell_row" style="width: 85px; text-align:center;"><?php if($order_by!='') echo $order_by; else echo '&nbsp;';?></div>
				<?php } else {?>
				<div class="cell_row" style="width: 85px; text-align:center;"><?php if($order_by!='') echo $order_by; else echo '&nbsp;';?></div>
				<div class="cell_row" style="width: 85px; text-align:center;"><?php echo $tans;?></div>
				<?php } ?>
				<div class="cell_row" style="width: 97px; text-align:center;" title="<?php echo $row_shocat['transaction_ID'];?>"><?php echo $transaction_ID."...";?></div>
				<div class="cell_row" style="width: 80px; text-align:center;"><?php echo $row_shocat['tran_date']."&nbsp;".$p;?></div>
				<div class="cell_row" style="width: 80px; text-align:center;" id="d_<?php echo $product_id;?>"><?php echo $shipped_date;?><?php echo $shipped;?></div>
				<div class="cell_row" style="width: 75px;"><?php echo $editItem;?><br /><?php echo $feedback;?></div>
			
			</div>
			<?php
			$i++;
		}
	}
	else{
	?>
	                  Records not found..
	<?php
	}
	?>
		
	</div>
	<div align="center" style="float:left; width:660px; text-align:center">
		<?php		   
		   $link="mySwapen&ord=".$_REQUEST['ord']."&by=".$asc_desc."";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link);							   
		?>    
	</div>	
	
</form>

</div>
<div class="fullbox_bot">&nbsp;</div>
</div>
<hr style="float:left; width:500px; display:none;" id="hr_line_tran_history" />
</div>
</div>

<div class="popup_box" style="display:none; position:absolute; background:#FFFFFF;" id="contact_user_box"> 
  <div class="popup_box_in" style="height:200px;">
      <div style="float: left; margin: 0 30px; padding: 5px; text-align: left; width: 85%;" id="msgbox">
	   
	<table cellspacing="3" cellpadding="5" border="0" width="100%" class="boldGreyNotes">
		<tbody>
			<tr>
				<td width="16%">Subject</td>
				<td width="24%"><input type="text" id="txtSub" name="txtSub" value="Transaction Referenced"/></td>
				<td width="12%">&nbsp;</td>
				<td width="48%">&nbsp;</td>
			</tr>
			<tr>
				<td>Your Message </td>
				<td colspan="3"><textarea id="txtQuery" rows="5" cols="40" name="txtQuery"></textarea></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td colspan="3">
					<input type="button" value="Send Message" name="submit" class="refer_btn" onclick="send_message()" />
					<input type="button" onclick="$('#contact_user_box').hide();" value="Close" name="Submit2" class="refer_btn" />
					<input type="hidden" value="" name="recieverid" id="recieverid" />
					<input type="hidden" value="" name="productname">
					<input type="hidden" value="" name="jobid" id="jobid" />
					<input type="hidden" name="type" id="type" />
				</td>
			</tr>
	     </tbody>
	</table>
      </div>
      
  </div>
</div>


<div id="ship_verify_box" class="srlink_popup2" style="display:none; width:280px;">
	<div style="width:270px;"><span style="float:right; padding:5px; cursor:pointer;" onclick="$('#ship_verify_box').hide();">x</span></div>
	<div class="srlinkpp2_text" id="trans_box" style="width:270px;">
		Tracking # <input type="text" maxlength="10" size="9" id="item_code" /><br /><br />
		Date. <select id="shipped_date" style="width:48px;">
			<option value="">dd</option>
			<?php
			for($i=1;$i<=31;$i++) {
				if($i<=9) $i = '0'.$i;
				echo '<option value="'.$i.'">'.$i.'</option>';
			}
			?>
		</select>
		<select id="shipped_month" style="width:48px;">
			<option value="">mm</option>
			<?php
			for($i=1;$i<=12;$i++) {
				if($i<=9) $i = '0'.$i;
				echo '<option value="'.$i.'">'.$i.'</option>';
			}
			?>
		</select>
		<select id="shipped_year" style="width:65px;">
			<option value="">yyyy</option>
			<?php
			for($i=date('Y');$i<=date('Y')+10;$i++) {
				echo '<option value="'.$i.'">'.$i.'</option>';
			}
			?>
		</select><br /><br />
		<input type="hidden" id="product_id" />
		<input type="button" class="refer_btn" value="Mark as Shipped" style="margin-left:5px;" onclick="verify_item_code()" /> 
	</div>
</div>

<script type="text/javascript">
function show_contact_user_box(sold_by_id,product_id,product_name)
{
	//href='sendowner.php?ownerid=".$sold_by_id."&jobid=".$product_id."&type=M'
	var ntop = (( $(window).height() - $('#contact_user_'+product_id).height()) / 2+$(window).scrollTop()) - 100;
	var nleft = ( $(window).width() - $('#contact_user_'+product_id).width()) / 2+$(window).scrollLeft();

	$('#recieverid').val(sold_by_id);
	$('#jobid').val(product_id);
	$('#type').val('M');
	$('#productname').val(product_name);
	$('#contact_user_box').css({'left': '', 'top':ntop}).fadeIn('slow');
	
}
function send_message()
{
	var recieverid 	= $('#recieverid').val();
	var jobid 	= $('#jobid').val();
	var type 	= $('#type').val();
	var txtSub 	= $('#txtSub').val();
	var txtQuery 	= $('#txtQuery').val();
	var productname	= $('#productname').val();
	var url = "<?php echo $base_url;?>sendowner.php";
	$.post(url,
	{ 'recieverid': recieverid,'jobid':jobid, 'type':type, 'txtSub':txtSub, 'txtQuery':txtQuery},
		function(data)
		{
			
			if(trim(data)=='ok')
			{
				
				$('#msgbox').html('<h1 style="float:left; width:100%; text-align:center;">Message sent successfully</h1><div align="center" style="float:left; width:98%; padding:5px;"><input type="button" onclick="$(\'#contact_user_box\').hide();" name="" value="Close" class="refer_btn" style="margin:0px; height:30px;" /></div>');
			}
			else
			{
				$('#msgbox').html('<h1 style="float:left; width:100%; text-align:center;">Message not sent.</h1><div align="center" style="float:left; width:98%; padding:5px;"><input type="button" onclick="$(\'#contact_user_box\').hide();" name="" value="Close" class="refer_btn" style="margin:0px; height:30px;" /></div>');
			}
		},
	'html'
	);
}
function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function show_ship_verify_box(product_id)
{
	//$('#trans_box').html('Trans No. <input type="text" maxlength="10" size="9" id="item_code" /><br /><br /><input type="hidden" id="product_id" /><input type="button" class="refer_btn" value="Verify" style="margin-left:5px;" onclick="verify_item_code()" /> &nbsp; <input type="button" class="refer_btn" value="Close" onclick="$(\'#ship_verify_box\').hide();" style="margin-left:5px;" />');
	var pos = $('#down_arrow_'+product_id).position();
	var ntop = pos.top;
	var nleft = parseFloat(pos.left)-150;
	$('#ship_verify_box').css({'left': nleft, 'top':ntop}).fadeIn('slow');
	$('#product_id').val(product_id);
	
}
function verify_item_code()
{
	var product_id = $('#product_id').val();
	var item_code = $('#item_code').val();
	var shipped_date = $('#shipped_date').val();
	var shipped_month = $('#shipped_month').val();
	var shipped_year = $('#shipped_year').val();
	var send_date = '';
	if(shipped_date!='' && shipped_month!='' && shipped_year!='')
	{
		var send_date = shipped_year+'-'+shipped_month+'-'+shipped_date;
	}
	
	if(item_code=='')
	{
		alert('Please enter a valid code');
	}
	else
	{
		var url = "<?php echo $base_url;?>verify_item_code.php";
		$.post(url,
		{ 'item_code': item_code,'product_id':product_id,'shipped_date':send_date},
		function(data)
		{
			if(trim(data)!='fail')
			{
				data = data.split('###');
				$('#trans_box').html('You have successfully verified ('+item_code+') '+data[3]+' with buyer '+data[1]+' '+data[2]+' <br /> <input type="button" class="refer_btn" value="Close" onclick="$(\'#ship_verify_box\').hide();" style="margin-left:5px;" />');
				$('#d_'+product_id).html(data[0]+' <font style="font-weight:bold; color:pink" title="Local Pickup">P</font>');
			}
			else
			{
				$('#trans_box').html('The 10 digit buyer code does not match our records, please try again. If you are sure this is correct code please contact us at support@swapen.com <br /><input type="button" class="refer_btn" value="Close" onclick="$(\'#ship_verify_box\').hide();" style="margin-left:5px;" />');
			}
			
		},
		'html');
	}
}


	
		function validatechk()
		{
			var chks = document.getElementsByName('chk');
			var checkCount = 0;
			for (var i = 0; i < chks.length; i++)
			{
			if (chks[i].checked)
			{
				checkCount++;
			}
			}
			if (checkCount == 0)
			{
				alert("Please select one transaction.");
				return false;
			}
			else
			{
				
				var selected = new Array();
				$('#tbox input:checked').each(function() {
				    selected.push($(this).val());
				
				});
				var arr_cnt = selected.length;
				var temp;
				for(i=0;i<arr_cnt;i++)
				{
					if(i==0)
						temp = selected[i];
					else
						temp+="_"+selected[i]; 
				}
				//alert(temp);
				var x=document.getElementById("form_his");
				x.action="amazon_refund.php?trans="+temp;
				x.submit();
			}
			return true;
		}




</script>